/*********************************************************************************************************************************
* Auto-load User Details on Mouse-Over using Ajax, Jquery and PHP
* Written by Vasplus Programming Blog
* Website: www.vasplus.info
* Email: info@vasplus.info


**********************************Copyright Information****************************************************************************
* This script has been released with the aim that it will be useful.
* Please, do not remove this copyright information from the top of this page.
* If you want the copyright info to be removed from the script then you have to buy this script.
* This script must not be used for commercial purpose without the consent of Vasplus Programming Blog.
* This script must not be sold.
* All Copy Rights Reserved by Vasplus Programming Blog


*******************************************************Installation Information*****************************************************
*To use this user details popup script, just wrap your content with a link "<a>this is a content</a>" containing the attributes 

class="vpb_link_attribute" 
vasplus_programming_blog_user_details="Your Users IDs,Your Usernames" 

as specified in the code at the index page of this demonstration and that's all for the popup to work on mouse-over
************************************************************************************************************************************/



/* We have used window.load event to be sure that the page is fully loaded before the popup can be called */
//$(window).load(function(){ //Uncomment this line if you want your page to finish loading before a user details begin to load on mouse over
	$(document).ready(function()
	{
		/* Global variables declaration */
		var vpb_time_popup_is_allowed_to_stay = 1800,
		vpb_info,
		vpb_uid,
		vpb_username,
		vpb_time_out = null,
		vpb_popup_box = $('<div id="vpb_load_user_details_main_wrapper"><div id="vpb_load_user_details_displayer"></div></div>').appendTo($( "body" ));
		
		$('.vpb_link_attribute').click( function()
		{
			/* Format for 'vasplus_programming_blog_user_details' tag: user_id, user_name */
			vpb_info = $(this).attr('vasplus_programming_blog_user_details').split(',');
			vpb_uid = vpb_info[0];
			vpb_username = vpb_info[1];
	
			/* If there is no valid user info in the url vasplus_programming_blog_user_details tag, no need to popup blank field */
			if (vpb_uid == "" || vpb_username == "")
				return false;
	
			if (vpb_time_out)
				clearTimeout(vpb_time_out);
				
			/* Position the popup correctly beside the mouseover info */
			var vpb_popup_position = $(this).offset();
			var width = $(this).width();
			vpb_popup_box.css({
				left: (vpb_popup_position.left - width) - 510 + 'px',
				top: vpb_popup_position.top - 45 + 'px'
			});
			
			/* Pass the User ID and Username to a variable dataString */
			var dataString = 'com:' + vpb_uid + ',num:' + vpb_username;
			//$.get("./api/getKd100.php",{com:com,num:num},
			// $.get("./api/getKd100.php",{com:com,num:num},
				// function(data)
				// {			
					// $("#resData").html(data);
				// }
			// );
			
			$.ajax({
				type: "GET",
				url: "./api/getKd100.php",
				data: {com:vpb_uid,num:vpb_username},
				cache: false,
				beforeSend: function()
				{
					/* This shows loading the popup box */
					$('#vpb_load_user_details_displayer').show().html("");
					$("#vpb_load_user_details_displayer").html('<div style="padding-top:8px;padding-bottom:10px;font-family:Verdana, Geneva, sans-serif; font-size:16px;font-weight:bold;color:gray;">Loading <img src="images/loading.gif" align="absmiddle" /></div>');
				},
				success: function(response)
				{
					/* This displays the popup box */
					$("#vpb_load_user_details_displayer").html(response);
					//$("#vpb_load_user_details_displayer").append($(response).fadeIn());
				}
			});
			vpb_popup_box.css('display', 'block');
		});
	
		$('.vpb_link_attribute').live('mouseout', function()
		{
			if (vpb_time_out)
				clearTimeout(vpb_time_out);
				
			vpb_time_out = setTimeout(function()
			{
				vpb_popup_box.css('display', 'none');
			}, vpb_time_popup_is_allowed_to_stay);
		});
	
		/* This allows the mouse over event over i info without hiding the info */
		$('#vpb_load_user_details_main_wrapper').mouseover(function()
		{
			if (vpb_time_out)
				clearTimeout(vpb_time_out);
		});
	
		/* This hides the popup box when a user mouseout of the box */
		$('#vpb_load_user_details_main_wrapper').mouseout(function()
		{
			if (vpb_time_out)
				clearTimeout(vpb_time_out);
				
			vpb_time_out = setTimeout(function()
			{
				vpb_popup_box.css('display', 'none');
			}, vpb_time_popup_is_allowed_to_stay);
		});
	});
//});